//<!-- Version 7.2.000.06 -->
//<!--(C) 2000-2006 Genesys Telecommunications Laboratories, Inc. -->
var _browser;

function getBrowserInfo()
{   // convert all characters to lowercase to simplify testing
    var agt = navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    major   = parseInt(navigator.appVersion);
    minor   = parseFloat(navigator.appVersion);

    nav     = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)));

    nav2    = (this.nav && (this.major == 2));
    nav3    = (this.nav && (this.major == 3));
    nav4    = (this.nav && (this.major == 4));

    nav4up  = this.nav && (this.major >= 4);

    nav6up  = this.nav && (this.major >= 5);
    navonly = (this.nav && (agt.indexOf(";nav") != -1));

    ie      = (agt.indexOf("msie") != -1);
    ie3     = (this.ie && (this.major == 2));
    ie4     = (this.ie && (this.major == 4));
    ie4up   = this.ie  && (this.major >= 4);

    if(nav6up)
        _browser = "NS6UP";
    else if(nav4up)
        _browser = "NS4UP";
    else if(ie4up)
        _browser = "IE4UP";
    else
        _browser = "UNSUPPORTED";

    return _browser;
}

/******************************************************************/
var IsIE    = true;

function IsBrowserIE ()
{
  CheckBrowser();
  return IsIE;
}

function CheckBrowser()
{
  if (navigator.appVersion.indexOf("MSIE") == -1)
    IsIE  = false;
  else
    IsIE  = true;
}
/********************************************************************************/
// external functions
// Object with nama=Name from frame with nama=Frame
function GetObjFromFrame (Frame, Name) //
{
  var FrameObj = GetFrame (Frame);

  if (FrameObj == null)
  {
    catcherror ("GetObjFromFrame:: can't find frame " + Frame);
    return null;  //===>>
  }
  return LookForObject( FrameObj, Name );   //===>>
}

// Object from current frame with nama=Name
function GetObj (Wnd, Name)
{
  return LookForObject( Wnd, Name );  //===>>
}

//Get frame with name=Name
function GetFrame (Name)
{
  return ProcessFrames(top, Name);
}
/********************************************************************************/
// internal functions
function ProcessFrames(Wnd, Name)
{
  if (Wnd.name != null && Wnd.name.toUpperCase() == Name.toUpperCase())
    return Wnd; //===>>

  var Len = Wnd.frames.length;
  var NextFrame;
  var i = 0;
  for (i = 0; i < Len; i++, NextFrame = null)
  {
    NextFrame = Wnd.frames[i];

    if (NextFrame.name != null && NextFrame.name.toUpperCase() == Name.toUpperCase())
      break;

    if (NextFrame.frames.length > 1)
      if ( null != (NextFrame = ProcessFrames(NextFrame, Name)) )
        break;
  }
  return NextFrame;//===>>
}

function LookForObject( FrameObj, Name )
{
  var Obj,
    Len = FrameObj.document.all.length,
    DocObj = FrameObj.document;

  for(var i = 0; i < Len; i++)
    if (((Obj = DocObj.all(i)) != null) && Obj.name != null && Obj.name.toUpperCase() == Name.toUpperCase())
      return Obj; //===>>

  return null;  //===>>
}

function trim(mystring)
{
    var reLead, reTail;
    reLead = /^\s*/;
    reTail = /\s*$/;

    return(mystring.replace(reLead, '').replace(reTail, ''));
}

function TrimSpace(ScriptIdUrl)
{
  var i = 0;
  var strParsedUrl  = "";
  var strlURL   = ScriptIdUrl;

  for (i = 0; i < strlURL.length; i++)
  {
    if (strlURL.charAt(i) != " ")
    {
      strParsedUrl = strlURL.substr (i, strlURL.length-i);
      break;
    }
  }
  strlURL = strParsedUrl;
  for (i = strlURL.length-1; i >= 0 ; i--)
  {
    if (strlURL.charAt(i) != " ")
    {
      strParsedUrl = strlURL.substr (0, i+1);
      break;
    }
  }
  return strParsedUrl;
}

function evaluate(raw)
{
  var ms = ";";
  var as = "&";
  var i;

  var meth = new String(raw);
  if (meth.charAt(0) == ms)
    meth = meth.substring(1, meth.length);

  meth = meth.split(ms);

  for (i = 0; i < meth.length; i++)
  {
    var obj = new String(meth[i]);
    if (obj == "null")
      meth[i] = null;
    else if (obj.charAt(0) == as)
      meth[i] = UnmaskArray(obj);
    else
      meth[i] = UnmaskString(obj);
  }

  var evalme = meth[0] + "(";
  for (i = 1; i < meth.length; i++)
  {
    evalme = evalme + "meth[" + i + "]";
    if (i + 1 < meth.length)
      evalme = evalme + ", ";
  }

  evalme = evalme + ")";

  if (isUserFunctionExist (meth[0]))
    eval(evalme);
  else
    alert ("Event handler not exist for " + evalme);
}

function UnmaskString (strIn)
{
  if (strIn == null || strIn.length == 0)
    return null;

  var i;
  var strCurrent = "";

  for (i=0; i < strIn.length; i++)
  {
    if (i < strIn.length-2)
    {
      var trinity = strIn.substr(i, 3);
      if (trinity == "%3B")
      {
        i += 2;
        strCurrent += ";";
      }
      else if (trinity == "%26")
      {
        i += 2;
        strCurrent += "&";
      }
      else if (trinity == "%25")
      {
        i += 2;
        strCurrent += "%";
      }
      else if (trinity == "%0D")
      {
        i += 2;
        strCurrent += "\n";
      }
      else if (trinity == "%0A")
      {
        i += 2;
        strCurrent += "\r";
      }
      else if (trinity == "%22")
      {
        i += 2;
        strCurrent += "\"";
      }
      else
        strCurrent += strIn.charAt(i);
    }
    else
      strCurrent += strIn.charAt(i);
  }

  return strCurrent;
}

function UnmaskArray (strIn)
{
  if (strIn == null || strIn.length ==0 || strIn.charAt(0) != "&")
    return null;

  var iLength = 1;
  var i;

  var aOut = new Array(1);
  var strCurrent = "";

  iLength = 0;
  for (i=1; i < strIn.length; i++)
  {
    if (strIn.charAt(i) == "&")
    {
      aOut[iLength] = strCurrent;
      strCurrent = "";
      iLength++;
      continue;
    }

    if (i < strIn.length-2)
    {
      var trinity = strIn.substr(i, 3);
      if (trinity == "%3B")
      {
        i += 2;
        strCurrent += ";";
      }
      else if (trinity == "%26")
      {
        i += 2;
        strCurrent += "&";
      }
      else if (trinity == "%25")
      {
        i += 2;
        strCurrent += "%";
      }
      else if (trinity == "%0D")
      {
        i += 2;
        strCurrent += "\n";
      }
      else if (trinity == "%0A")
      {
        i += 2;
        strCurrent += "\r";
      }
      else if (trinity == "%22")
      {
        i += 2;
        strCurrent += "\"";
      }
      else
        strCurrent += strIn.charAt(i);
    }
    else
      strCurrent += strIn.charAt(i);
  }

  aOut[iLength] = strCurrent;
  return aOut;
}

function EncodeArray(inData)
{
  var strOut = "&";
  var i;
  for (i = 0; i < inData.length; i++)
  {
    if (inData[i] == null)
      break;
    strOut += MaskSimbols (inData[i]);
    if (i != inData.length-1)
       strOut += ";";
  }
  return strOut;
}

function MaskSimbols (strIn)
{
  var ch;
  var strOut = "";
  var j;
  for (j = 0; j < strIn.length; j++)
  {
    ch = strIn.charAt(j);
    if (ch == ';')
      strOut += "%3B";
    else if (ch == '&')
      strOut += "%26";
    else if (ch == '%')
      strOut += "%25";
    else if (ch == '\n')
      strOut += "%0D";
    else if (ch == '\r')
      strOut += "%0A";
    else if (ch == '\"')
      strOut += "%22";
    else
      strOut += ch;
  }
  return strOut;
}

function isUserFunctionExist(name)
{
  if(eval( "typeof("+name+")" )=='function')
    return true;
  else
    return false;
}

function GetSubmitParametr(Path, Name)
{
  var Params        = "";
  var ParamsArray     = null;
  var KVPair        = null;
  var i         = 0;
  var Parametr      = "";

  Params    = Path.substr(1, Path.length);
  ParamsArray = Params.split ("&");

  if (ParamsArray != null)
  {
    for (i = 0; i < ParamsArray.length; i++)
    {
      KVPair = ParamsArray[i].split ("=");
      if (KVPair != null)
      {
        if (KVPair[0] != null && KVPair[1] != null)
        {
          if (KVPair[0].toUpperCase() == Name.toUpperCase())
          {
            Parametr = KVPair[1];
            break;
          }
        }
      }
    }
  }
  return Parametr;
}

function GetArrayFromQueryString(Path)
{
  var Params        = "";
  var ParamsArray     = null;
  var KVPair        = null;
  var i         = 0;
  var OutArray      = null;
  var Value;

  Params    = Path.substr(1, Path.length);
  ParamsArray = Params.split ("&");

  if (ParamsArray != null)
  {
    OutArray = new Array (ParamsArray.length*2);
    for (i = 0; i < ParamsArray.length; i++)
    {
      KVPair = ParamsArray[i].split ("=");
      if (KVPair != null)
      {
        if (KVPair[0] != null && KVPair[1] != null)
        {
          Value = unescape(KVPair[0]);
          Value = Value.replace(/\+/g, " ");
          OutArray[i*2] = Value;

          Value = unescape(KVPair[1]);
          Value = Value.replace(/\+/g, " ");
          OutArray[i*2+1] = Value;
        }
      }
    }
  }
  return OutArray;
}

function UnEscape (strData)
{
  var result = unescape(strData);
  result = result.replace(/\+/g, " ");
  return result;
}

function GetTime()
{
  var mDate = new Date();
  var strTime;

  if (mDate.getMinutes() < 10)
    strTime = mDate.getHours() + ":0" + mDate.getMinutes();
  else
    strTime = mDate.getHours() + ":" + mDate.getMinutes();

  if (mDate.getSeconds() < 10)
    strTime += ":0" + mDate.getSeconds() + " ";
  else
    strTime += ":" + mDate.getSeconds() + " ";

  return strTime;
}

function GetMinuteString(nSeconds)
{
  var n = nSeconds - (-30); // Convert to numeric (by subtracting) & add 30 to round up
  var nMinutes = (n - (n % 60)) / 60; // Make n evenly divisible by 60, and divide
  if(nMinutes == 0)
    nMinutes = 1;
  var strReturn = nMinutes + " minute";
  if(nMinutes != 1)
    strReturn = strReturn + "s"
  return strReturn;
}

function GetTimeString (seconds)
{
  var strOut = "";
  if (seconds != 0)
  {
    if (seconds/3600 > 1)
    {
      strOut = strOut + Math.floor(seconds/3600) + " hour(s)<br>";
      seconds = seconds%3600;
    }
    if (seconds/60 > 1)
    {
      strOut = strOut + Math.floor(seconds/60) + " minute(s)<br>";
      seconds = seconds%60;
    }
    strOut = strOut + seconds + " second(s)";
  }
  else
    strOut = "0 second(s)";
  return strOut;
}

function CheckNonASCIIChars (strIn)
{
  var i = 0;
  var ch = "";
  for (i=0; i < strIn.length; i++)
  {
    ch = strIn.charAt(i);
    if ( ch < "-" || ch > "z")
      return false;
  }
  return true;
}

function CheckEmail (emailStr)
{

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function setSelection(objControl, Value)
{
  for( c=0; c < objControl.options.length; c++ )
  {
    if( objControl.options[c].value == Value )
    {
      objControl.options[c].selected = true;
      break;
    }
  }
}

function getSelectedOption(opt)
{
  var c = null;
  var ret = null;
  for(c=0; c < opt.options.length; c++)
  {
    if(opt.options[c].selected)
    {
      ret = (opt.options[c].value == null || opt.options[c].value.length == 0)
                ? opt.options[c].text : opt.options[c].value;
      break;
    }
  }

  return ret;
}

function double_digit(Value)
{
    var temp = "";
    if( Value <= -10 || Value >=10 )
        temp = "" + Value;
    else
        if (Value < 0)
           temp =  "-0" + ((-1)*Value);
        else
           temp = "0" + Value;
    return temp;
}

function GetUTCTime(date)
{
  var UserDate = new Date (date);
  var strTime = "";

  strTime = strTime + double_digit(UserDate.getUTCMonth()+1) + "/";
  strTime = strTime + double_digit(UserDate.getUTCDate()) + "/";
  strTime = strTime + (UserDate.getUTCFullYear()) + " ";

  strTime = strTime + double_digit(UserDate.getUTCHours()) + ":";
  strTime = strTime + double_digit(UserDate.getUTCMinutes()) + " ";

  var d = new Date();
  strTime = strTime + double_digit(d.getTimezoneOffset()/60) + ":" + double_digit(d.getTimezoneOffset()%60);
  return strTime;
}

function ConvertTime(UTCtime)
{
  if (UTCtime == "")
    return "";
  UTCtime = UTCtime.substring (0, UTCtime.lastIndexOf(' '));
  var UserDate = new Date(UTCtime);
  var newDate = new Date();
  newDate.setUTCDate(UserDate.getDate());
  newDate.setUTCMonth(UserDate.getMonth());
  newDate.setUTCFullYear(UserDate.getFullYear());
  newDate.setUTCMinutes(UserDate.getMinutes());
  newDate.setUTCHours(UserDate.getHours());
  newDate.setUTCSeconds(0);
  return newDate.toLocaleString();
}

function PositiveSub (i1, i2)
{
	var i3 = i1-i2;
	if (i3 > 0 )
		return i3;
	return 0;

}

function ConvertSecondsToString(iSeconds) 
{
        var iDays=Math.round(iSeconds/(60*60*24));
        iSeconds=PositiveSub (iSeconds, iDays*(60*60*24));

        var iHours=Math.round(iSeconds/(60*60));
        iSeconds=PositiveSub(iSeconds, iHours*(60*60));

        var iMinutes=Math.round(iSeconds/60);
        iSeconds=PositiveSub(iSeconds, iMinutes*60);

        var strOut = ""; 

        if (iDays != 0)
	{
		strOut = strOut + iDays + " day";
		if (iDays > 1)
			strOut = strOut + "s";
		strOut = strOut + " ";
	}

        if (iHours != 0)
	{
		strOut = strOut + iHours + " hour";
		if (iHours > 1)
			strOut = strOut + "s";
		strOut = strOut + " ";
	}
        if (iMinutes != 0)
	{
		strOut = strOut + iMinutes + " minute";
		if (iMinutes > 1)
			strOut = strOut + "s";
		strOut = strOut + " ";
	}
        if (iSeconds != 0)
	{
		strOut = strOut + iSeconds + " second";
		if (iSeconds > 1)
			strOut = strOut + "s";
		strOut = strOut + " ";
	}
 	if (strOut == "")
		strOut = "0 seconds";

        return strOut; 
}